//
//  HmailListDetalViewController.m
//  NursingManage
//
//  Created by Zhen Huang on 17/5/11.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "HmailListDetalViewController.h"
#import "HmailListDetailTableViewCell.h"
@interface HmailListDetalViewController ()
<UITableViewDelegate,
UITableViewDataSource>
@property (nonatomic, copy) void(^clickedSmsButtonBlcok)();
@property (nonatomic, copy) void(^clickedPhoneButtonBlcok)();
@property (nonatomic, strong) UITableView *tabelView;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *job_num;
@property (nonatomic, copy) NSString *mobile_num;
@property (nonatomic, copy) NSString *address;
@property (nonatomic, copy) UIButton *smsButton;
@property (nonatomic, copy) UIButton *phoneButton;

@end

@implementation HmailListDetalViewController

- (instancetype)initWithName:(NSString *)name
                     job_num:(NSString *)job_num
                  mobile_num:(NSString *)mobile_num
                     address:(NSString *)address
{
    if (self) {
        self.name = name;
        self.job_num = job_num;
        self.mobile_num = mobile_num;
        self.address = address;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tabelView];
}
- (UITableView *)tabelView
{
    if (!_tabelView ) {
        _tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - 50)];
        _tabelView.dataSource = self;
        _tabelView.delegate = self;
        _tabelView.tableFooterView = [[UIView alloc]init];
        [_tabelView registerClass:[HmailListDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tabelView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HmailListDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.clickedSmsButtonBlcok = ^{
        
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"sms:%@",self.mobile_num];
        UIWebView * callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
        
    };
    cell.clickedPhoneButtonBlcok = ^(){
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",self.mobile_num];
        UIWebView * callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
    };
    

    if (indexPath.row != 2||self.mobile_num.length == 0) {
        cell.smsButton.hidden = YES;
        cell.phoneButton.hidden = YES;
    }else {
        cell.smsButton.hidden = NO;
        cell.phoneButton.hidden = NO;
    }
    
    switch (indexPath.row) {
        case 0:
            cell.contentNameLabel.text = @"姓名:";
            cell.contentLabel.text = self.name;
            cell.contentLabel.textAlignment = NSTextAlignmentRight;
            break;
        case 1:
            cell.contentNameLabel.text = @"工号:";
            cell.contentLabel.text = self.job_num;
            cell.contentLabel.textAlignment = NSTextAlignmentRight;
            break;
            
        case 2:
        {
            cell.contentNameLabel.text = @"电话:";
            cell.contentLabel.textAlignment = NSTextAlignmentRight;
            cell.contentLabel.text = self.mobile_num;
        }
            break;
            
        case 3:
            
            cell.contentNameLabel.text = @"家庭住址:";
            cell.contentLabel.frame = CGRectMake(ScreenWidth - 250, 10, 240, 20);
            cell.contentLabel.textAlignment = NSTextAlignmentRight;
            cell.contentLabel.text = self.address;
        
            break;
            

        default:
            break;
    }
    return cell;
}

- (void)smsButtonAction:(UIButton *)sender{
    
    self.clickedSmsButtonBlcok();
}


- (void)phoneButtonAction:(UIButton *)sender{
    
    self.clickedPhoneButtonBlcok();
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
